<?php
namespace app\model;

use think\Model;

class Banner extends Model
{
    protected $table='banner';
    public function findAll()
    {
        return Banner::select()->toArray();
    }
    public function pageFindAll($page)
    {
        $pageNo = $page['pageNo'];
        $pageSize = $page['pageSize'];
        if ($pageNo<=0) {
            $pageNo=0;
        }
        if ($pageSize<=0) {
            $pageSize=10;
        }
        $list= Note::$db->query('select * from banner limit '.$pageNo*$pageSize.','.$pageSize);
        $data=['page'=>[
            'pageSize'=>$pageSize,
            'pageNo'=>$pageNo,
            'count'=>count($list),
        ],
        'result'=>$list
    ];
        return $data;
    }
    public function add($data)
    {
        return Banner::replace()->insert($data);
    }

    public function findById($id)
    {
        $data = Banner::where(['bannerId'=>$id])->find();
        return $data;
    }

    public function updateBanner($data)
    {
        try {
            $Banner = Banner::find($data->bannerId);
            $Banner->name= $data->name;
            $Banner->imageUrl= $data->imageUrl;
            $Banner->updateTime= $data->updateTime;
            $Banner->bState= $data->bState;
            return  $Banner->save();
        } catch (\Throwable $th) {
        }
        return false;
    }
    public function deleteBanner($bannerId)
    {
        Banner::where(['bannerId'=>$bannerId])->delete();
        return true;
    }

    public function filter()
    {
    }
    public function hotBanner()
    {
        return $list= Note::$db->query("select * from banner where bState='1' order by updateTime desc , createTime desc ");
    }
}
